﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.DAL.DAHelpers;
using SMS.Entities;
using SMS.Entities.Menu;

namespace SMS.DAL
{
   public class MenuDA:BaseDA<Menu>
    {
        public override List<Menu> SearchObject(string userName, string menuGroup)
        {
            #region PROCEDURE
            /*
             ALTER PROC [dbo].[USP_SELECT_MENUS] --'Master'
@MenuGroup VARCHAR(50)
AS
SELECT M.MenuID, M.MenuName, M.MenuPath from Menu M
INNER JOIN 
MenuGroup MG ON M.MenuGroup=MG.MenuGroupID
WHERE MG.MenuGroupName=@MenuGroup
             */
            #endregion
            try
            {
                dbHelper.AddParameter("@Search_Text", string.IsNullOrWhiteSpace(menuGroup) ? string.Empty : menuGroup);
                var reader = dbHelper.ExecuteReader("USP_SELECT_MENUS", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
                var list = new List<Menu>();
                while (reader.Read())
                {
                    list.Add(GetMenuObject(reader));
                }
                //LogActivity(userName, string.Format("Searched city with text {0}", menuGroup), null);
                return list;
            }
            catch (Exception ex)
            {
                LogException(userName, ex, null);
                throw new Exception("Error while getting menus");
            }

           // throw new NotImplementedException();
        }
        public override bool DeleteObject(string userName, Menu tObject)
        {
            throw new NotImplementedException();
        }
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override List<Menu> GetObjectList(string userName, DateTime fromDate, DateTime toDate)
        {
            throw new NotImplementedException();
        }
        public override Menu SaveObject(string userName, Menu tObject)
        {
            throw new NotImplementedException();
        }
        public override string ToString()
        {
            return base.ToString();
        }
        private Menu GetMenuObject(System.Data.Common.DbDataReader reader)
        {
            int i = -1;
            Menu obj = new Menu();
            if (!reader.IsDBNull(++i))
                obj.MenuID = reader.GetInt32(i);
            if (!reader.IsDBNull(++i))
                obj.MenuName = reader.GetString(i);
            if (!reader.IsDBNull(++i))
                obj.MenuPath = reader.GetString(i);
            return obj;
        }
    }
}
